import Layout from "@/core/page/index";
import module from "../module";
const pageViews = [];
const requireComponent = require.context("../views", true, /i\.js$/);
requireComponent.keys().map((fileName) => {
  const nameList = fileName.split("/");
  if (nameList.length == 3 && nameList[2] == "i.js") {
    const name = nameList[1];
    pageViews.push({
      name: "",
      path: `/${module.code}/${name}`,
      meta: requireComponent(fileName).default,
    });
  }
});
pageViews.push(
  {
    // 添加Preview页面
    name: "设计大屏",
    path: `/${module.code}/build`,
    meta: {
      name: "设计大屏",
      isNotMenu: true,
      isTab: false,
    },
    isNotMenu: true,
  },
  {
    name: "Preview大屏",
    path: `/${module.code}/preview`,
    meta: {
      name: "Preview大屏",
      isNotMenu: true,
      isTab: false,
    },
    isNotMenu: true,
  },
  {
    name: "轮播Preview",
    path: `/${module.code}/swiperPreview`,
    meta: {
      name: "轮播Preview",
      isNotMenu: true,
      isTab: false,
    },
    isNotMenu: true,
  }
);
export default pageViews.map((t) => {
  const componentName = t.path.replace(`/${module.code}`, "");
  if (t.isNotMenu) {
    return {
      path: t.path,
      name: t.name,
      meta: t.meta,
      props: true,
      component: () =>
        import(
          /* webpackChunkName: "[request]" */ `../views${componentName}/index`
        ),
    };
  } else {
    return {
      path: t.path,
      component: Layout,
      redirect: `${t.path}/index`,
      children: [
        {
          path: "index",
          name: t.name,
          meta: t.meta,
          component:async() => {
            let cpn = await import(/* webpackChunkName: "[request]" */ `../views${componentName}/index`);
            cpn.default.name = `page${t.path.replace(/\//g,'-')}-index`;
            return cpn;
          }
        },
      ],
    };
  }
});
